<?php
/**
 * ランキングバッチコントローラー
 *
 * @package  app
 * @extends  Controller
 */
class Controller_Manage_Mysql extends Controller_Manage {
	/**
	 * スロークエリ
	 *
	 * @access  public
	 * @return  Response
	 */
	public function action_slowquery() {
		$sql = "SELECT DATE_FORMAT(MAX(query_time),'%s.%f') as querytime,DATE_FORMAT(MAX(lock_time),'%s.%f') as locktime,rows_sent,sql_text";
		$sql .= " FROM mysql.slow_log";
		$sql .= " WHERE db='commesodo_development'";
		$sql .= " GROUP BY sql_text";
		$sql .= " ORDER BY querytime DESC, rows_sent DESC";
		$sql .= " LIMIT 100";

		// コメント数
		$list = DB::query($sql) -> execute() -> as_array();

		return Response::forge(View::forge('manage/table',array('list' => $list)), D_HTTP_UPDATE);
	}

	/**
	 * スロークエリ削除
	 *
	 * @access  public
	 * @return  Response
	 */
	public function action_slowqueryclear() {
		$sql = "TRUNCATE mysql.slow_log";
		DB::query($sql) -> execute();

		return Response::forge(null, D_HTTP_UPDATE);
	}

}
